package cn.kgc.itrip.controller;


import cn.kgc.itrip.dto.Dto;
import cn.kgc.itrip.service.impl.TokenService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/api")
public class TokenController {

    @Resource
    private TokenService tokenService;

    /**
     * token的置换
     * @param request
     * @return
     */
    @PostMapping(value = "/retoken",produces = "application/json")
    public Dto reToken(HttpServletRequest request){
        String token = request.getHeader("token");
        String userAgent = request.getHeader("user-agent");
        Dto dto= null;
        try {
            dto = tokenService.retoken(token,userAgent);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dto;
    }
}
